const connection = require('../../sql');

class UserService {
	// 查询用户
	async findUser(username) {
		// 仅通过用户名查询用户，获取存储的哈希密码
		const statement = `SELECT id, username, pwd FROM sys_user WHERE username = ? AND del_flag = 'F'`;
		const [result] = await connection.execute(statement, [username]);
		return result[0]; // 返回包含哈希密码的用户对象
	}
	// 更新用户登录时间
	async updateLoginTime(id) {
		const date = new Date();
		const statement = `UPDATE sys_user SET last_login_time = ? WHERE id = ? AND del_flag = 'F'`;
		const [result] = await connection.execute(statement, [date, id]);
		return result;
	}
	//   获取登录用户信息
	async findUserInfo(username) {
		const statement = `select id, email, logo, nickname, username, phone from sys_user where username = ? AND del_flag = 'F'`;
		const [result] = await connection.execute(statement, [username]);
		return result[0];
	}
}
module.exports = new UserService();
